<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>深拷贝3</title>
</head>
<body>
<script>
//    var json={"a":"1","b":"2"};
//    var str=JSON.stringify(json);
//    console.log(str);
//    var json2=JSON.parse(str);
//    console.log(typeof json2);//object

    function deepClone(obj){
        var str,newobj=obj.constructor===Array?[]:{};
        if(typeof obj!=='object'){
            return ;
        }else if(window.JSON){
            str=JSON.stringify(obj);
            newobj=JSON.parse(str);
        }else{
            for(var i in obj){
                newobj[i]=typeof obj[i]==='object' ?
                    deepClone(obj[i]):obj[i];
            }
        }
        return newobj;
    }
    var a={"a":"1","b":["sad","asdas"]};
    var b=deepClone(a);
    b.b[1]="sdsfsdfdfgs";
    console.log(a);
    console.log(b);

</script>
</body>
</html>